package com.fy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fy.entity.Search;
import com.fy.entity.Subway;
import com.fy.service.ISubwayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 晓岩
 * @since 2022-05-26
 */
@RestController
@RequestMapping("/subway")
public class SubwayController {
    @Autowired
    ISubwayService subwayService;

    /**
     * 分页 模糊查询
     */
    @RequestMapping("list")
    public Page<Subway> list(@RequestBody Search search){
        QueryWrapper<Subway> wrapper = new QueryWrapper<>();
        if(StringUtils.hasText(search.getName())){
            wrapper.like("name",search.getName());
        }
        if(search.getStart()!=null){
            wrapper.eq("start",search.getStart());
        }
        if(search.getDate1()!=null){
            wrapper.ge("date",search.getDate1());
        }
        if(search.getDate2()!=null){
            wrapper.le("date",search.getDate2());
        }
        Page<Subway> page = new Page<>(search.getPage(),search.getPageSize());
        return subwayService.page(page, wrapper);
    }
}
